package com.qkl.xiatang.app.entity.feed;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.qkl.xiatang.app.utils.AppDateUtils;
import com.qkl.xiatang.app.utils.AppUtils;
import lombok.Data;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 配(喂)料配置
 */
@Data
@TableName(value = "feed_alloc_config")
public class FeedAllocConfig {

    @TableId(type= IdType.ASSIGN_ID)
    private String id;

    private String companyId;

    private String templateId;

    private String name;

    private Integer serialNo;

    private Integer startHour;

    private Integer endHour;

    private Integer querySeparTime;

    private Integer sort;

    private Integer serialFlag;

    private Time startTime;

    private Time endTime;

    private Date createTime;


    public Date toAllocDate(Date allocDate){
        if(this.nextDate()){
            return AppDateUtils.addDays(allocDate,1);
        }
        return allocDate;
    }

    public Date toStartTime(Date allocDate){
        if(null != startTime){
            return toDate(allocDate,startTime);
        }
        return toDate(allocDate,startHour);
    }

    public Date toEndTime(Date allocDate){
        if(null != endTime){
            return toDate(allocDate,endTime);
        }
        return toDate(allocDate,endHour);
    }

    private Date toDate(Date allocDate,Integer hour){
        return AppDateUtils.toFeedDate(allocDate,hour);
    }
    private Date toDate(Date allocDate,Time time){
        return AppDateUtils.toFeedDate(allocDate,time);
    }

    public boolean firstDate(){
        return !nextDate();
    }

    public boolean nextDate(){
        return Integer.valueOf(1).equals(serialFlag);
    }
}
